package com.gxa.modules.deviceManager.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.deviceManager.entity.EquipmentClassification;
import com.gxa.modules.deviceManager.entity.EquipmentManagement;
import com.gxa.modules.deviceManager.entity.MaintenanceRecord;
import com.gxa.modules.deviceManager.form.EquipmentClassificationForm;
import com.gxa.modules.deviceManager.service.EquipmentClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "设备分类")
@RestController
@Slf4j
public class EquipmentClassificationController {
    @Autowired
    private EquipmentClassificationService equipmentClassificationService;

    @ApiOperation(value="设备分类查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "classifyName",value ="查询条件-设备分类名称",dataType ="String"),
    }
    )
    @GetMapping("/equipmentClassification/list")
    public Result<PageUtils> list(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        PageUtils pageUtils = this.equipmentClassificationService.queryByPage(params);
        return new Result<PageUtils>().ok(pageUtils);
    }

    @ApiOperation(value="设备分类添加接口")
    @PostMapping("/equipmentClassification/add")
    public Result add(@RequestBody EquipmentClassificationForm equipmentClassificationForm){
        log.info("----body-----{}----",equipmentClassificationForm);
        EquipmentClassification equipmentClassification=new EquipmentClassification(equipmentClassificationForm);
        this.equipmentClassificationService.save(equipmentClassification);
        return new Result().ok();
    }

    @ApiOperation(value="设备分类删除接口")
    @DeleteMapping ("/equipmentClassification/delete")
    public Result delete(@RequestBody List<Integer> ids){
        log.info("----param-----{}----",ids);
        this.equipmentClassificationService.removeByIds(ids);
        return new Result().ok();
    }

    @ApiOperation(value="设备分类修改接口")
    @PutMapping ("/equipmentClassification/update")
    public Result update(@RequestBody EquipmentClassificationForm equipmentClassificationForm){
        log.info("----param-----{}----",equipmentClassificationForm);
        EquipmentClassification equipmentClassification=new EquipmentClassification(equipmentClassificationForm);
        this.equipmentClassificationService.updateById(equipmentClassification);
        return new Result().ok();
    }

}
